package com.mall.biz.mall;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.mall.MallMarketingService;
import com.mall.pojo.MallMarketing;
import com.mall.pojo.MallMarketingExample;
import com.mall.pojo.MallMarketingExample.Criteria;
import com.mall.query.MallMarketingQuery;

@Service
public class MallMarketingBizImpl {
	@Autowired
	private MallMarketingService mallMarketingService;

	/**
	 * 查询单个个优惠方式
	 * @param query
	 * @return
	 */
	public MallMarketing getMallMarketingByQuery(MallMarketingQuery query) {
		List<MallMarketing> mallMarketingList = getMallMarketingListByQuery(query);
		MallMarketing mallMarketing = null;
		if (mallMarketingList != null && mallMarketingList.size() > 0) {
			mallMarketing = mallMarketingList.get(0);
		}
		return mallMarketing;
	}

	/**
	 * 获取优惠方式列表
	 * @param query
	 * @return
	 */
	public List<MallMarketing> getMallMarketingListByQuery(MallMarketingQuery query) {
		MallMarketingExample example = new MallMarketingExample();
		Criteria criteria = example.createCriteria();
		criteria.andCommOnlyKeyEqualTo(query.getOnlyKey());
		criteria.andMallIdEqualTo(query.getMallId());
		if (query.getMallItemId() != null && query.getMallItemId() > 0) {
			criteria.andItemIdEqualTo(query.getMallItemId());
		}
		if (query.getType() != null && query.getType() > 0) {
			criteria.andDiscountTypeEqualTo(query.getType());
		}

		List<MallMarketing> mallMarketingList = this.mallMarketingService.getMallMarketingListBy(example);
		return mallMarketingList;
	}

}
